%config InlineBackend.figure_format='retina'
from spacepy import pycdf
import math as mt
import matplotlib.pyplot as plt
import numpy as np
import scipy.fft as sf
import datetime
import bisect
import matplotlib.patches as patches
import matplotlib.dates as mdates
from IPython.display import display,Math
import matplotlib as mpl
from ai import cdas
import datetime
from matplotlib import pyplot as plt
import pandas as pd
from matplotlib.gridspec import GridSpec
import matplotlib.animation as animation
Use the cdas package to obtain data.
### for observation ###
data = cdas.get_data(
'sp_phys',
'STA_L1_MAG_RTN',
datetime.datetime(2010, 1, 1, 0, 0, 0),
datetime.datetime(2010, 1, 1, 1, 0, 1),
['BFIELD'],
cdf=True # download data in CDF format
)
### convert to the dataframe of pandas ###
d = {'BR': data['BFIELD'][:,0], 'BT': data['BFIELD'][:,1], 'BN':data['BFIELD'][:,2]}
df0 = pd.DataFrame(data=d,index=data['Epoch'][:])
df0.index.name='time'
##########################################
You need to define these different from the cell which called matplotlib.pyplot
color='#3f3f3f'
mpl.rcParams['font.family'] = 'Arial'
mpl.rcParams['font.size']=14
mpl.rcParams['figure.dpi']=120
mpl.rcParams['axes.linewidth'] = 1.5
mpl.rcParams['xtick.major.size']=5
mpl.rcParams['xtick.minor.size']=4
mpl.rcParams['ytick.major.size']=5
mpl.rcParams['ytick.minor.size']=3
mpl.rcParams['xtick.major.width']=1
mpl.rcParams['ytick.major.width']=1
#mpl.rcParams['mathtext.default'] = 'regular'
#mpl.rcParams['xtick.top'] = 'True'
#mpl.rcParams['ytick.right'] = 'True'
mpl.rcParams['xtick.direction'] = 'out'
mpl.rcParams['ytick.direction'] = 'out'
#mpl.rcParams['axes.grid'] = 'True'
#mpl.rcParams['axes.xmargin'] = '0' #'.05'
#mpl.rcParams['axes.ymargin'] = '.05'
#mpl.rcParams['savefig.facecolor'] = 'None'
#mpl.rcParams['savefig.edgecolor'] = 'None'
mpl.rcParams['savefig.bbox'] = 'tight'
mpl.rcParams['axes.edgecolor']=color
mpl.rcParams['xtick.color'] =color
mpl.rcParams['ytick.color'] =color
mpl.rcParams['axes.labelcolor']=color
mpl.rcParams['animation.html'] = 'jshtml'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=(6,6),sharex='all',dpi=80)
ax.xaxis.set_tick_params(which='major', top='on')
ax.yaxis.set_tick_params(which='both' ,right='on')
ax.set_ylim(0.1,10)
ax.set_yscale('log')
ax.set_xlabel(r'x$\alpha$a')
plt.show()
fig, ax = plt.subplots(nrows=3,ncols=1,figsize=(6,6),sharex='all',dpi=80)
plt.subplots_adjust(hspace=0.)
for ic in range(3):
ax[ic].xaxis.set_tick_params(which='major', top='on', direction='in', length=5, width=2)
plt.show()
It is better to use 'pcolormesh' rather than 'imshow'
x=np.linspace(0,2*np.pi,1000)
y=np.logspace(-1,1,1000)
X,Y=np.meshgrid(x,y)
Z1=np.cos(X)*np.sin(Y)
fig,ax=plt.subplots(figsize=(16,4))
im1=ax.pcolormesh(X,Y,Z1,cmap='jet',shading='auto')
ax.set_yscale('log')
fig.colorbar(im1,ax=ax,label='test',pad=0.02)
<matplotlib.colorbar.Colorbar at 0x11dec7590>
fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(8, 4))
ax[2].set_xlim(0,10)
### add a rectangle patch ###
rect = patches.Rectangle((2, 0), 3, 3+2*fig.subplotpars.hspace, color='grey',alpha=.25, clip_on=False,transform=ax[2].get_xaxis_transform())
ax[2].add_patch(rect)
#############################
plt.show()
### date time format ###
fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(8, 4))
ax[2].plot(df0.index[:], df0['BR'][:])
### add a rectangle patch ###
#start='2010-01-01 00:20:00'
#end ='2010-01-01 00:30:00'
#startplt = mdates.date2num(start)
#endplt = mdates.date2num(end)
#rect = patches.Rectangle((startplt, 0), endplt-startplt, 3+2*fig.subplotpars.hspace, color='grey',alpha=.25, clip_on=False, transform=ax[2].get_xaxis_transform())
start = datetime.datetime(2010, 1, 1, 0,20,0)
end = datetime.datetime(2010, 1, 1, 0,30,0)
rect = patches.Rectangle((start, 0), end-start, 3+2*fig.subplotpars.hspace, color='grey',alpha=.25, clip_on=False, transform=ax[2].get_xaxis_transform())
ax[2].add_patch(rect)
#############################
#ax[2].set_xlim(start,end)
plt.show()
/Users/mnakanot/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py:102: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters. To register the converters: >>> from pandas.plotting import register_matplotlib_converters >>> register_matplotlib_converters() warnings.warn(msg, FutureWarning)
fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(8, 4))
ax[2].set_xlim(0,10)
ax[2].axvline(4, 0, 3+2*fig.subplotpars.hspace, ls='dashed', color='k', clip_on=False)
plt.show()
### for observation ###
fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(8, 4))
start = datetime.datetime(2010, 1, 1, 0,20,0)
ax[2].plot(df0.index[:], df0['BR'][:])
ax[2].axvline(start, 0, 3+2*fig.subplotpars.hspace, ls='dashed', color='k', clip_on=False)
plt.show()
fig,ax=plt.subplots(nrows=1,ncols=1,figsize=(8,4))
# Move left y-axis and bottim x-axis to centre, passing through (0,0)
ax.spines['left'].set_position('zero')
ax.spines['bottom'].set_position('center')
# Eliminate upper and right axes
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# Show ticks in the left and lower axes only
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.set_xlim(-5,20)
ax.set_ylim(-5,5)
ax.set_aspect('equal')
plt.show()
x=np.linspace(0,1,1000)
y=np.linspace(-1,1,1000)
X,Y=np.meshgrid(x,y)
Z1=np.abs(X*Y)
fig,ax=plt.subplots(figsize=(8,4))
im1=ax.imshow(Z1,cmap='jet',aspect='auto',origin='lower',extent=[x[0],x[-1],y[0],y[-1]], norm=mpl.colors.LogNorm(vmin=1e-3,vmax=1e0))
fig.colorbar(im1,ax=ax,label='test',pad=0.02)
plt.show()
#### plot figure ###
fig, ax = plt.subplots(ncols=1, figsize=(6,6))
N_TICKS = 12
cmap = plt.cm.get_cmap('jet', N_TICKS) # 11 discrete colors
smap = ax.scatter(df0['BR'][:],df0['BT'][:],c=df0.index,cmap=cmap,marker='o',alpha=0.8)
smap.set_facecolor("none")
indexes = [df0['2010-01-01 00:00'].index[0], df0['2010-01-01 00:15'].index[0], df0['2010-01-01 00:30'].index[0], df0['2010-01-01 00:45'].index[0], df0['2010-01-01 01:00'].index[0]]
cb = fig.colorbar(smap, ax=ax, orientation='vertical', ticks= df0.loc[indexes].index.astype(int), label='hh:mm')
cb.ax.set_yticklabels([index.strftime('%H:%M') for index in indexes])
ax.set_xlabel(r'$B_R$ [nT]')
ax.set_ylabel(r'$B_T$ [nT]')
plt.show()
### plot figure ###
fig, ax = plt.subplots(ncols=1, figsize=(16,4))
ax.plot(df0.index, df0['BR'][:])
myfmt=mdates.DateFormatter('%H:%M:%S\n%d %b %Y')
ax.xaxis.set_major_formatter(myfmt)
plt.show()
fig7, f7_axs = plt.subplots(ncols=3, nrows=3)
gs = f7_axs[1, 2].get_gridspec()
# remove the underlying axes
for ax in f7_axs[1:, -1]:
ax.remove()
axbig = fig7.add_subplot(gs[1:, -1])
fig7.tight_layout()
widths = [2, 3, 1]
heights = [1, 3, 2]
#gs_kw = dict(width_ratios=widths, height_ratios=heights)
fig6, f6_axes = plt.subplots(ncols=3, nrows=3, figsize=(6,4), constrained_layout=True,gridspec_kw={'width_ratios':widths, 'height_ratios':heights}) #or gridspec_kw=gs_kw
### read the H number distribution ###
r =np.linspace(0, 70,100)
th=np.linspace(0,360,200,endpoint=True)/180*np.pi
R,Th=np.meshgrid(r,th)
### plot figure ###
#fig,ax=plt.subplots(nrows=2,figsize=(10,12))
fig=plt.figure(figsize=(12,3),dpi=80)
#plt.rcParams['font.size'] = 10
gs=GridSpec(1,3) # 2 rows, 3 columns
gs.update(wspace=0.1) # set the spacing between axes.
ax0=fig.add_subplot(gs[0,0:2]) # First row, first column
ax1=fig.add_subplot(gs[0,2], polar=True) # First row, second column
#fig.add_subplot(121)
#ax0.plot(mu,label='monthly')
#ax0.plot(mu.rolling("8760D").mean(),label='24 year')
#ax0.legend()
ax0.grid()
ax0.set_xlabel('time [year]')
ax0.set_ylabel(r'$\mu$')
#ax0.set_xlim(mu.index[154],mu.index[634])
#ax=fig.add_subplot(122, polar=True,facecolor='grey')
#CS=ax.pcolormesh(Th,R,data,cmap=plt.cm.get_cmap('coolwarm', 10))
#fig.colorbar(CS, ax=ax,shrink=0.8,ticks=np.linspace(0,0.1,11),label='$n_H$ [cm$^{-3}$]')
#CS=ax1.pcolormesh(Th,R,data2,cmap='coolwarm')
#fig.colorbar(CS, ax=ax1,shrink=1,label='$n_H$ [cm$^{-3}$]')
#ax1.plot(P10rphi[::2000]['phi']-np.pi, P10rphi[::2000]['R'],'k-')
#ax1.plot(V1rphi[::1000]['phi']-np.pi, V1rphi[::1000]['R'],'k-.')
#ax1.plot(V2rphi[::100]['phi']-np.pi, V2rphi[::100]['R'],'k--')
#ax1.grid(False)
#ax.clabel(CS, inline=1, fontsize=10)
#ax.set_yticklabels([])
#ax1.thetagrids([theta * 15 for theta in range(360//15)])
#ax1.set_rmax(70)
#ax1.set_rlabel_position(135/2)
#import matplotlib.text as txt
#ax1.text(177*np.pi/180,60,'P10')
#ax1.text(-10*np.pi/180,60,'V1')
#ax1.text( 30*np.pi/180,60,'V2')
#ax1.text(135/2*np.pi/180,82,'[au]')
#plt.colorbar()
#ax.grid(True)
#cmap = cm.get_cmap('PiYG', 11) # 11 discrete colors
#ax.set_thetamin(0)
#ax.set_thetamax(180)
#fig.tight_layout()
plt.show()
x=np.arange(200)
y=np.random.randn(200)
z=np.zeros(200)
plt.plot(x,z, 'red', lw=5)
plt.scatter(x,y, zorder=2.5)
plt.show()
Also setting gridspec_kw and width_ratios, you can adjust the size of figures.
xx=np.linspace(0,100*np.pi,1000)
yy=np.linspace(0, 2*np.pi,1000)
yy=np.cos(xx/4)*np.exp(-xx/100)
XX,YY=np.meshgrid(xx,yy)
ZZ=np.cos(XX/4)*np.exp(-XX/100)
fig, ax = plt.subplots(nrows=3, sharex=True, figsize=(16, 8))
plt.subplots_adjust(hspace=0.)
im0=ax[0].pcolormesh(XX,YY,ZZ,shading='nearest')
im1=ax[1].plot(xx,yy)
im2=ax[2].pcolormesh(XX,YY,ZZ*1e5,cmap='jet',shading='nearest')
fig.colorbar(im0,ax=ax[0],label='test' ,aspect=5, pad=0.01)
fig.colorbar(im2,ax=ax[2],label='test\ntest\ntest',aspect=5, pad=0.01)
cb = fig.colorbar(im0,ax=ax[1],aspect=5, pad=0.01)
cb.ax.set_visible(False)
plt.show()
widths = [2, 2, 2]
heights = [1, 1]
gs_kw = dict(width_ratios=widths, height_ratios=heights)
fig, ax = plt.subplots(ncols=3, nrows=2, constrained_layout=True,gridspec_kw=gs_kw)
Z=np.random.randn(20,20)
im1=ax[1,2].imshow(Z, aspect='auto')
fig.colorbar(im1, ax=ax[1,2])
plt.show()
x=np.arange(0.01,np.e,0.01)
y1=np.exp(-x)
y2=np.log(x)
fig,ax=plt.subplots(figsize=(8,4))
ax.plot(x,y1)
ax.set_ylabel('Y values for exp(-x)')
ax.set_xlabel('Same X for both exp(-x) and ln(x)')
ax2=ax.twinx()
ax2.plot(x,y2,'r')
ax2.set_xlim([0,np.e])
ax2.set_ylim([-5,1])
ax2.set_ylabel('Y values for ln(x)', color='r')
ax2.tick_params(axis='y', colors='r')
ax2.spines["right"].set_edgecolor('r')
ax3=ax.twinx()
ax3.spines["right"].set_position(("axes", 1.12))# move the spine of the second axes outwards
ax3.plot(x, np.sin(4*x),'g')
ax3.set_xlim([0,np.e])
ax3.set_ylim(-1,1)
ax3.set_ylabel('Y values for ln(x)', color='g')
ax3.tick_params(axis='y', colors='g')
ax3.spines["right"].set_edgecolor('g')
plt.show()
def update_anim(it):
fig.clf() #clear the figure
ax=fig.subplots(2, 2) #add subplots
fig.tight_layout() #reduce spacing around the figure
#for i in range(2):
# for j in range(2):
# ax[i,j].cla()
Z1=np.random.randn(N,N) #random numbers in 2D
Z2=np.random.randn(N,N) #random numbers in 2D
Z3=np.random.randn(N,N) #random numbers in 2D
Z4=np.random.randn(N,N) #random numbers in 2D
im1=ax[0,0].imshow(Z1 ,aspect='equal', origin='lower', cmap='Greys')
im2=ax[1,0].imshow(Z2 ,aspect='equal', origin='lower', cmap='Blues')
im3=ax[0,1].imshow(Z3 ,aspect='equal', origin='lower', cmap='Reds')
im4=ax[1,1].imshow(Z4 ,aspect='equal', origin='lower', cmap='Greens')
#im4=ax[1,1].plot(x,np.sin(it*x))
cb1=fig.colorbar(im1, ax=ax[0,0])
cb2=fig.colorbar(im2, ax=ax[1,0])
cb3=fig.colorbar(im3, ax=ax[0,1])
cb4=fig.colorbar(im4, ax=ax[1,1])
N=20
nt=20
x = np.linspace(-5, 5, N)
y = np.linspace(-5, 5, N)
X, Y = np.meshgrid(x, y)
fig=plt.figure(figsize=(8,8))
anim=animation.FuncAnimation(fig,update_anim,frames=nt)
plt.close()
anim
#anim.save('sample.gif', writer='imagemagick') #save the animation as a gif file
x=np.linspace(0,10,1000)
y1=np.zeros(1000)
y2=x**2/(1+x**2)
y3=x**(1/4)
fig, ax = plt.subplots()
ax.plot(x, y1, "k")
ax.plot(x, y2, "k")
ax.plot(x, y3, "k")
ax.fill_between(x, y1, y2, fc="w", hatch= "x") #{'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
ax.fill_between(x, y2, y3, fc="w", hatch="//")
ax.set_ylim(0,2)
plt.show()
def f(x, y):
return np.cos(x+y) ** 5 + np.cos(4 + y * x) * np.cos(-x)
x = np.linspace(0, 5, 100)
y = np.linspace(0, 5, 100)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure()
ax = plt.axes()
plt.imshow(Z, extent=[0, 5, 0, 5], origin='lower',
cmap='gnuplot')
plt.colorbar()
axins = ax.inset_axes([0.45, 0.4, 0.5, 0.5])
axins.imshow(Z, extent=[0, 5, 0, 5],
origin="lower",cmap='gnuplot')
# sub region of the original image
x1, x2, y1, y2 = 2, 3, 0.4, 1.4
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
axins.set_xticklabels('')
axins.set_yticklabels('')
ax.indicate_inset_zoom(axins)
plt.show()
x = np.arange(-10, 10, 0.1)
plt.plot(x, x**2)
ax=plt.axes([0.5, 0.6, 0.2, 0.2])
ax.plot(x, x)
ax.set_xlim(-5,5)
plt.show()
from matplotlib.patches import ConnectionPatch
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
# Draw a simple arrow between two points in axes coordinates
# within a single axes.
xyA = (0.2, 0.2)
xyB = (0.8, 0.8)
coordsA = "data"
coordsB = "data"
con = ConnectionPatch(xyA, xyB, coordsA, coordsB,
arrowstyle="->", shrinkA=5, shrinkB=5,
mutation_scale=20, fc="w")
ax1.plot([xyA[0], xyB[0]], [xyA[1], xyB[1]], "o")
ax1.add_artist(con)
# Draw an arrow between the same point in data coordinates,
# but in different axes.
xy = (0.0, 0.0)
coordsA = "data"
coordsB = "data"
con = ConnectionPatch(xyA=(0.3, 0.2), xyB=(0,0), coordsA=coordsA, coordsB=coordsB,
axesA=ax2, axesB=ax1,
arrowstyle="-", shrinkB=0)
ax2.add_artist(con)
# Draw a line between the different points, defined in different coordinate
# systems.
xyA = (0.6, 1.0) # in axes coordinates
xyB = (0.0, 0.2) # x in axes coordinates, y in data coordinates
coordsA = "axes fraction"
coordsB = ax2.get_yaxis_transform()
con = ConnectionPatch(xyA=xyA, xyB=xyB, coordsA=coordsA, coordsB=coordsB,
arrowstyle="-")
ax2.add_artist(con)
ax1.set_xlim(0, 1)
ax1.set_ylim(0, 1)
ax2.set_xlim(0, .5)
ax2.set_ylim(0, .5)
plt.show()
x=np.linspace(-5,5,200)
y=np.linspace(-4,4,200)
X, Y = np.meshgrid(x,y)
nr=1000
cx=-10+20*np.random.rand(nr)
cy=-5 +10*np.random.rand(nr)
k=np.zeros(nr)
for i in range(nr):
if cx[i]<0: k[i]=1
if cx[i]>0: k[i]=2
Jz=np.zeros((200,200))
for i in range(nr):
R=np.sqrt((X-cx[i])**2+(Y-cy[i])**2)
Jz=Jz+2*k[i]/(1+(k[i]*R)**2)**2
fig,ax = plt.subplots(nrows=1, ncols=3, sharex=True, figsize=(16,8))
im0=ax[0].contour( X, Y, Jz, levels=40, colors='grey',alpha=0.4)
im1=ax[1].contour( X, Y, Jz, levels=40, cmap='jet')
im2=ax[2].contourf(X, Y, Jz, levels=20, cmap='jet')
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
divider = make_axes_locatable(ax[2])
cax = divider.append_axes("top", size="5%", pad=0.1)
cb2=fig.colorbar(im2, cax=cax, ax=ax[2], orientation='horizontal')
cax.xaxis.set_ticks_position('top')
divider1 = make_axes_locatable(ax[1])
cax1 = divider1.append_axes("top", size="5%", pad=0.1)
cb1=fig.colorbar(im1, cax=cax1, ax=ax[1], orientation='horizontal', pad=0.05)
cax1.xaxis.set_ticks_position('top')
#cb1.ax.set_visible(False)
divider0 = make_axes_locatable(ax[0])
cax0 = divider0.append_axes("top", size="5%", pad=0.1)
cb2=fig.colorbar(im0, cax=cax0, ax=ax[0], orientation='horizontal', pad=0.05)
cax0.xaxis.set_ticks_position('top')
cb2.ax.set_visible(False)
#fig.colorbar(im2, cax=cax, ax=ax[1], orientation='horizontal', pad=0.05, anchor=(0.5, 1.0))
for i in range(3):
ax[i].set_aspect('equal')
plt.show()
plt.contourf(X,Y,Jz,levels=20,cmap='hot')
plt.contour( X,Y,Jz,levels=20,colors='white',linewidths=0.5)
plt.show()
Actually, there is no easy to plot it. Alternatively, you can use scatter (but points). If you really need multicolored lines, you can check here; [https://matplotlib.org/3.3.3/gallery/lines_bars_and_markers/multicolored_line.html]
x = np.linspace(0, 2*np.pi, 1000)
y = np.sin(10*x)*np.exp(-x)
z = np.sin(10*x)
fig, ax = plt.subplots()
im1=ax.scatter(x,y, s=10, c=z, edgecolor='none', cmap='bwr')
fig.colorbar(im1, ax=ax)
plt.show()
### discrete ###
n_lines = 5
x = np.linspace(0, 10, 100)
y = np.sin(x[:, None] + np.pi * np.linspace(0, 1, n_lines))
c = np.arange(1, n_lines + 1)
#cmap = mpl.cm.get_cmap('jet', n_lines)
#fig, ax = plt.subplots(dpi=100)
## Make dummie mappable
#dummie_cax = ax.scatter(c, c, c=c, cmap=cmap)
## Clear axis
#ax.cla()
#for i, yi in enumerate(y.T):
# ax.plot(x, yi, c=cmap(i))
#fig.colorbar(dummie_cax, ticks=c)
#plt.show();
cmap = plt.get_cmap("jet", len(c))
norm = mpl.colors.BoundaryNorm(np.arange(len(c)+1)+0.5,len(c))
sm = plt.cm.ScalarMappable(norm=norm, cmap=cmap)
sm.set_array([]) # this line may be ommitted for matplotlib >= 3.1
fig, ax = plt.subplots(dpi=100)
for i, yi in enumerate(y.T):
ax.plot(x, yi, c=cmap(i))
fig.colorbar(sm, ticks=c)
plt.show()
### continuous ###
n_lines = 5
x = np.linspace(0, 10, 100)
y = np.sin(x[:, None] + np.pi * np.linspace(0, 1, n_lines))
c = np.arange(1, n_lines + 1)
norm = mpl.colors.Normalize(vmin=c.min(), vmax=c.max())
cmap = mpl.cm.ScalarMappable(norm=norm, cmap=mpl.cm.jet)
cmap.set_array([])
fig, ax = plt.subplots(dpi=100)
for i, yi in enumerate(y.T):
ax.plot(x, yi, c=cmap.to_rgba(i + 1))
fig.colorbar(cmap, ticks=c)
plt.show();
np.random.seed(1234)
x = np.linspace(0, 360, 1000)
x_a = np.linspace(0, 360, 12)
y = 100*(1 - np.exp(-0.01*x))
y_a = 100*(1 - np.exp(-0.01*x_a)) + np.random.randn(12)
color='#545454'
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y, 'k', lw=1.5, alpha=0.8, label='theory')
ax.plot(x_a, y_a, 'o', color='none', markersize=10, markeredgewidth=3, markeredgecolor=color, alpha=0.8, label='experiment')
ax.spines['top' ].set_linewidth(0)
ax.spines['right' ].set_linewidth(0)
ax.spines['left' ].set_linewidth(2)
ax.spines['bottom'].set_linewidth(2)
ax.spines['left' ].set_color(color)
ax.spines['bottom'].set_color(color)
#ax.spines['right'].set_visible(False)
#ax.spines['left'].set_visible(False)
#ax.spines['top'].set_visible(False)
ax.tick_params(direction='out', length=6, width=2, colors=color, labelsize=14)
ax.set_xlim(0,370)
ax.set_ylim(0,105)
#ax.set_xticks([60*i for i in np.arange(7)])
#ax.set_yticks([0, 25, 50, 75, 100])
#ax.set_xticklabels([x for x in np.arange(7)], fontsize=14, color=color)
#ax.set_yticklabels([0,25,50,75, 100] , fontsize=14, color=color)
#ax.xaxis.label.set_color('red')
#ax.tick_params(axis='x', colors='red')`1
ax.set_xlabel('time (h)' , fontsize=14, color=color)
ax.set_ylabel('Conversion (%)', fontsize=14, color=color)
#plt.savefig('test.pdf')
plt.show()